//
//  NSString+Size.m
//  StaffTax
//
//  Created by 侯伟 on 2020/1/10.
//  Copyright © 2020 侯伟. All rights reserved.
//

#import "NSString+Size.h"

@implementation NSString (Size)

//计算制定字体大小的文字显示尺寸（系统默认字体）
- (CGSize)sizeWithFontSize:(CGFloat)fontSize width:(CGFloat)width{
    return [self sizeWithFont:FONT(fontSize) width:width];
}
//计算制定字体的文字显示尺寸
- (CGSize)sizeWithFont:(UIFont*)font width:(CGFloat)width{
    CGSize size = CGSizeMake(width, CGFLOAT_MAX);
    
    NSMutableParagraphStyle* style =  [NSMutableParagraphStyle new];
    style.lineBreakMode = NSLineBreakByWordWrapping;
    
    NSDictionary* attributes = @{NSFontAttributeName:font,NSParagraphStyleAttributeName:style};
    return [self boundingRectWithSize:size options:(NSStringDrawingUsesLineFragmentOrigin) attributes:attributes context:NULL].size;
}

@end
